#include "../Base/stdafx.h"
#include "XMLNode.h"
#include <boost/foreach.hpp>


XMLNode::XMLNode(): m_Parent(0)
{
	m_Pos = 0;
}

XMLNode::~XMLNode()
{
	BOOST_FOREACH(XMLNode* node, m_Children) delete node;
}

void XMLNode::SetParent( XMLNode* node )
{
	m_Parent = node;
}

XMLNode* XMLNode::AddChild( XMLNode* node )
{
	m_Children.push_back(node);
	node->SetParent(this);
	return node;
}

void XMLNode::SetStartElement( const tstring& elem )
{
	m_StartElem = elem;
}

void XMLNode::AddValue( const pair<tstring, tstring>& values )
{
	m_Values.insert(values);
}

void XMLNode::SetText( const tstring& text )
{
	m_Text = text;
}

const tstring& XMLNode::GetStartElem() const
{
	return m_StartElem;
}

const tstring& XMLNode::GetText() const
{
	return m_Text;
}

const tstring& XMLNode::GetValue( const tstring& key ) const
{
	return m_Values.find(key)->second;
}

const XMLNode* XMLNode::GetNextChild() const
{
	if(m_Pos >= (int)m_Children.size()) 
		return NULL;
	else 
	{
		++m_Pos;
		return m_Children.at(m_Pos-1);
	}
}

const XMLNode* XMLNode::GetParent() const
{
	return m_Parent;
}